package com.fitz.serializer;

import com.alibaba.fastjson.JSONObject;

/**
 * @author fitz 2020-5-6 19:49
 */
public class JSONSerializer implements Serializer {
    /**
     * 序列化算法
     *
     * @return
     */
    @Override
    public byte getSerializerType() {
        return SerializerType.JSON;
    }

    /**
     * 序列化
     *
     * @param object
     * @return
     */
    @Override
    public byte[] serialize(Object object) {
        return JSONObject.toJSONBytes(object);
    }

    /**
     * 反序列化
     *
     * @param clazz
     * @param bytes
     * @return
     */
    @Override
    public <T> T deSerialize(Class<T> clazz, byte[] bytes) {
        return JSONObject.parseObject(bytes,clazz);
    }
}
